//
//  XQAccountCancelController.m
//  JoinPeso
//
//  Created by 小琦 on 2024/11/21.
//

#import "XQAccountCancelController.h"
#import "XQCustomEngeLabel.h"
#import "XQPopupAnimView.h"
#import "XQPrivacyPopView.h"
#import "XQprivacyView.h"
#import "XQUserController.h"

@interface XQAccountCancelController ()
@property (nonatomic,strong) XQCustomEngeLabel *customEngleLb;
@property (nonatomic,strong) UIImageView *warningImageView;
@property (nonatomic,strong) UILabel *warningLb;
@property (nonatomic,strong) XQprivacyView *privacyView;
@property (nonatomic,strong) UIButton *accountCancelBtn;
@property (nonatomic,strong) UIView *contentView;
@property (nonatomic,strong) UILabel *contentLb;
@property (nonatomic,strong) UIButton *repaidBtn;
@end

@implementation XQAccountCancelController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self makeNav];
    [self makeUI];
    [self makeConstraints];
}

- (void)makeNav {
    [self.navigationBar setTitle:@"Account cancelation"];
}

- (void)makeUI {
    self.view.backgroundColor = kCardColor;
    [self.view addSubview:self.customEngleLb];
    [self.view addSubview:self.warningImageView];
    [self.view addSubview:self.warningLb];
    [self.view addSubview:self.privacyView];
    [self.view addSubview:self.accountCancelBtn];
    [self.view addSubview:self.contentView];
    [self.contentView addSubview:self.contentLb];
    [self.contentView addSubview:self.repaidBtn];
}

- (void)makeConstraints {
    [self.customEngleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo([UIScreen mainScreen].topHeight + 20);
        make.left.equalTo(@12);
        make.right.equalTo(@-12);
    }];
    [self.warningImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.customEngleLb.mas_bottom).offset(24);
        make.left.equalTo(@12);
        make.width.equalTo(@21);
        make.height.mas_equalTo(18);
    }];
    [self.warningLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.warningImageView);
        make.left.equalTo(self.warningImageView.mas_right).offset(6.5);
    }];
    [self.accountCancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-[[UIScreen mainScreen] bottomHeight] - 20);
        make.left.equalTo(@12);
        make.right.equalTo(@-12);
        make.height.mas_equalTo(45);
    }];
    [self.privacyView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.accountCancelBtn.mas_top).offset(-20);
        make.left.equalTo(@29);
    }];
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.warningLb.mas_bottom).offset(20);
        make.left.equalTo(@12);
        make.right.equalTo(@-12);
        make.height.mas_equalTo(300);
    }];
    [self.contentLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(@20);
        make.left.equalTo(@14);
        make.right.equalTo(@-14);
    }];
    [self.repaidBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentLb.mas_bottom).offset(79);
        make.left.equalTo(@10);
        make.right.equalTo(@-10);
        make.height.mas_equalTo(44);
    }];
}

- (void)accountClick {
    if (!self.privacyView.radioButton.selected) {
        [XQToast showMsg:@"Please read and agree to the Privacy Policy"];
        return;
    }
    
    [XQHUD showLoadingInView:self.view];
    @weakify(self)
    [XQAFNetworking getWithUrl:[XQNetManager getAbsolutePath:@"/direct/aviation"] pars:@{} callback:^(_Bool success, id  _Nonnull responseObject, NSError * _Nonnull error) {
        @strongify(self);
        [XQHUD hideLoadindInView:self.view];
        if ([responseObject[@"concept"] integerValue] == 0) {
            [[NSUserDefaults standardUserDefaults] setObject:@"" forKey:@"continuous"];
            [[XQNetManager sharedInstance].globalDic setValue:@"" forKey:@"continuous"];
           
            [self.navigationController popViewControllerAnimated:YES];
            [self.navigationController popViewControllerAnimated:YES];

            [XQRouter jumpToHome];
        }else {
            [XQToast showMsg:responseObject[@"loon"]];
        }
        
    }];
}

#pragma mark - lazy

- (XQCustomEngeLabel *)customEngleLb {
    if (!_customEngleLb) {
        _customEngleLb = [[XQCustomEngeLabel alloc] init];
        _customEngleLb.edgtInsets = UIEdgeInsetsMake(12, 6, 12, 6);
        _customEngleLb.layer.cornerRadius = 15;
        _customEngleLb.layer.masksToBounds = YES;
        _customEngleLb.numberOfLines = 0;
        _customEngleLb.backgroundColor = kOrangeColor;
        _customEngleLb.text = @"Please carefully read the agreement belowto confirmcancellation";
        _customEngleLb.textAlignment = NSTextAlignmentCenter;
        _customEngleLb.textColor = [UIColor whiteColor];
        _customEngleLb.font = [UIFont systemFontOfSize:16];
    }
    return _customEngleLb;
}

- (UIImageView *)warningImageView {
    if (!_warningImageView) {
        _warningImageView = [[UIImageView alloc] init];
        _warningImageView.image = [UIImage imageNamed:@"user_warnning"];
    }
    return _warningImageView;
}

- (UILabel *)warningLb {
    if (!_warningLb) {
        _warningLb = [[UILabel alloc] init];
        _warningLb.text = @"pay attention to";
        _warningLb.textColor = kBlackTextColor;
        _warningLb.font = [UIFont boldSystemFontOfSize:16];
    }
    return _warningLb;
}

- (UIButton *)accountCancelBtn {
    if (!_accountCancelBtn) {
        _accountCancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_accountCancelBtn setTitle:@"Account cancellation" forState:UIControlStateNormal];
        [_accountCancelBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _accountCancelBtn.backgroundColor = kBlueTextColor;
        _accountCancelBtn.titleLabel.font = [UIFont boldSystemFontOfSize:20];
        _accountCancelBtn.layer.cornerRadius = 22.5;
        [_accountCancelBtn addTarget:self action:@selector(accountClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _accountCancelBtn;
}

- (XQprivacyView *)privacyView {
    if (!_privacyView) {
        _privacyView = [[XQprivacyView alloc] initWithViewController:self];
        [_privacyView setPrivacyPrefix:@"I have read and agreed to the above"];
        [_privacyView setPrivacyValue:@""];
    }
    return _privacyView;
}

- (UIView *)contentView {
    if (!_contentView) {
        _contentView = [[UIView alloc] init];
        _contentView.backgroundColor = [UIColor whiteColor];
        _contentView.layer.cornerRadius = 15;
    }
    return _contentView;
}

- (UILabel *)contentLb {
    if (!_contentLb) {
        _contentLb = [[UILabel alloc] init];
        _contentLb.text = @"The account cannot be restored after cancellation. In order to ensure the security of your account, please confirm that the account-related services have been handled correctly before the application and pay attention to the following provisions";
        _contentLb.numberOfLines = 0;
        _contentLb.textColor = kBlackTextColor;
        _contentLb.font = [UIFont systemFontOfSize:14];
        _contentLb.textAlignment = NSTextAlignmentCenter;
    }
    return _contentLb;
}

- (UIButton *)repaidBtn {
    if (!_repaidBtn) {
        _repaidBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_repaidBtn setTitle:@"All loans have been repaid" forState:UIControlStateNormal];
        [_repaidBtn setTitleColor:kOrangeColor forState:UIControlStateNormal];
        _repaidBtn.backgroundColor = [kOrangeColor colorWithAlphaComponent:0.2];
        _repaidBtn.layer.cornerRadius = 15;
    }
    return _repaidBtn;
}

@end
